package com.fish.yssb.ui.page.activity.setPara;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.text.method.DigitsKeyListener;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsoluteLayout;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fish.yssb.R;
import com.fish.yssb.ui.page.activity.base.BaseActivity;
import com.fish.yssb.ui.page.util.PrefeneceUtil;
import com.fish.yssb.ui.page.util.TopToastUtil;
import com.fish.yssb.ui.page.widget.CustomDialog;
import com.jaeger.library.StatusBarUtil;


/**
 * A login screen that offers login via email/password.
 */
public class SetParaTwoActivity extends BaseActivity implements OnClickListener {
    private static final String TAG = SetParaListActivity.class.getSimpleName();

    LinearLayout tv_back;
    EditText et_deveveid;
    EditText ed_msisdn;
    EditText et_ip;

    TextView tv_tab1,tv_tab2,tv_tab3,tv_tab4;
    View v_tab1,v_tab2,v_tab3,v_tab4;

    RelativeLayout rl_tab1,rl_tab2,rl_tab3,rl_tab4;
    TextView  tv_save,et_cs,et_tcp,et_btl,et_sjw,et_tzw,et_zyfs,tv_set,et_tcp2,et_cs2,et_port2,et_ip_bak2,et_ip2,et_cklx;
    private RelativeLayout ll_para_2, ll_para_3,ll_para_4,ll_para_5,ll_para_6,ll_para_22,ll_para_23,ll_para_11;
    private CustomDialog choosePicDialog;

    private LinearLayout ll_area1,ll_area2;
    private int sevice_type,net_type;

    public static void start(Context context) {
        Intent intent = new Intent(context, SetParaTwoActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sevice_type = -1;
        net_type = -1;
        StatusBarUtil.setTransparent(this);
        StatusBarUtil.setDarkMode(this);
        setContentView(R.layout.activity_setpara_two);
        initview();
        initData();
    }

    private void initData()
    {

      String  para2_et_tcp = PrefeneceUtil.getData("para2_et_tcp","1",false);
        net_type  = Integer.parseInt(para2_et_tcp);
        getClicke(net_type);




    }


    //初始化视图
    @SuppressLint("WrongViewCast")
    private void initview() {
        //登录层、下拉层、其它登录方式层
        tv_back = findViewById(R.id.tv_back);
        tv_save = findViewById(R.id.tv_save);
        et_ip = findViewById(R.id.et_ip);
        ll_para_2 = findViewById(R.id.ll_para_2);
        ll_para_3 = findViewById(R.id.ll_para_3);
        ll_para_4 = findViewById(R.id.ll_para_4);
        ll_para_5 = findViewById(R.id.ll_para_5);
        ll_para_11 = findViewById(R.id.ll_para_11);
        et_cklx = findViewById(R.id.et_cklx);
        ll_para_6 = findViewById(R.id.ll_para_6);
        ll_para_22 = findViewById(R.id.ll_para_22);
        ll_para_23 = findViewById(R.id.ll_para_23);
        et_tcp2 = findViewById(R.id.et_tcp2);
        et_cs2 = findViewById(R.id.et_cs2);
        ll_area2 = findViewById(R.id.ll_area2);
        ll_area1 = findViewById(R.id.ll_area1);
        et_tcp = findViewById(R.id.et_tcp);
        et_cs = findViewById(R.id.et_cs);
        et_zyfs = findViewById(R.id.et_zyfs);

        et_port2 = findViewById(R.id.et_port2);
        et_ip_bak2 = findViewById(R.id.et_ip_bak2);
        et_ip2 = findViewById(R.id.et_ip2);




        et_btl = findViewById(R.id.et_btl);
        et_sjw = findViewById(R.id.et_sjw);
        et_tzw = findViewById(R.id.et_tzw);

        tv_set = findViewById(R.id.tv_set);
        tv_set.setOnClickListener(this);
        ll_para_2.setOnClickListener(this);
        ll_para_3.setOnClickListener(this);
        ll_para_4.setOnClickListener(this);
        ll_para_5.setOnClickListener(this);
        ll_para_6.setOnClickListener(this);
        ll_para_22.setOnClickListener(this);
        ll_para_23.setOnClickListener(this);
        ll_para_11.setOnClickListener(this);
        tv_back.setOnClickListener(this);

        rl_tab1 = findViewById(R.id.rl_tab1);
        rl_tab2 = findViewById(R.id.rl_tab2);
        rl_tab3 = findViewById(R.id.rl_tab3);
        rl_tab4 = findViewById(R.id.rl_tab4);

        tv_tab1 = findViewById(R.id.tv_tab1);
        tv_tab2 = findViewById(R.id.tv_tab2);
        tv_tab3 = findViewById(R.id.tv_tab3);
        tv_tab4 = findViewById(R.id.tv_tab4);

        v_tab1 = findViewById(R.id.v_tab1);
        v_tab2 = findViewById(R.id.v_tab2);
        v_tab3 = findViewById(R.id.v_tab3);
        v_tab4 = findViewById(R.id.v_tab4);

        rl_tab1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                getClicke(1);
            }
        });
        rl_tab2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                getClicke(2);
            }
        });
        rl_tab3.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                getClicke(3);
            }
        });
        rl_tab4.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                getClicke(4);
            }
        });

        String digits = "0123456789.";
        et_ip2.setInputType(InputType.TYPE_CLASS_NUMBER);
        et_ip2.setKeyListener(DigitsKeyListener.getInstance(digits));

        et_ip_bak2.setInputType(InputType.TYPE_CLASS_NUMBER);
        et_ip_bak2.setKeyListener(DigitsKeyListener.getInstance(digits));
    }

    private void getClicke(int type)
    {
        v_tab1.setVisibility(View.GONE);
        v_tab2.setVisibility(View.GONE);
        v_tab3.setVisibility(View.GONE);
        v_tab4.setVisibility(View.GONE);

        rl_tab1.setBackgroundColor(Color.parseColor("#FFFFFF"));
        rl_tab2.setBackgroundColor(Color.parseColor("#FFFFFF"));
        rl_tab3.setBackgroundColor(Color.parseColor("#FFFFFF"));
        rl_tab4.setBackgroundColor(Color.parseColor("#FFFFFF"));

        tv_tab1.setTextColor(Color.parseColor("#333333"));
        tv_tab2.setTextColor(Color.parseColor("#333333"));
        tv_tab3.setTextColor(Color.parseColor("#333333"));
        tv_tab4.setTextColor(Color.parseColor("#333333"));

        switch (type)
        {
            case 1:
                net_type = 1;
                ll_area2.setVisibility(View.VISIBLE);
                ll_area1.setVisibility(View.GONE);
                rl_tab1.setBackgroundColor(Color.parseColor("#F7F7F7"));
                tv_tab1.setTextColor(Color.parseColor("#0D635B"));
                v_tab1.setVisibility(View.VISIBLE);

                et_tcp2.setText(PrefeneceUtil.getData("para2_et_tcp2","TCP",false));
                et_cs2.setText(PrefeneceUtil.getData("para2_et_et_cs2","客户端",false));
                et_port2.setText(PrefeneceUtil.getData("para2_et_port2","",false));
                et_ip_bak2.setText(PrefeneceUtil.getData("para2_et_ip_bak2","",false));
                et_ip2.setText(PrefeneceUtil.getData("para2_et_ip2","",false));

                break;
            case 2:
                net_type = 2;
                ll_area2.setVisibility(View.GONE);
                ll_area1.setVisibility(View.VISIBLE);
                ll_para_11.setVisibility(View.VISIBLE);
                rl_tab2.setBackgroundColor(Color.parseColor("#F7F7F7"));
                tv_tab2.setTextColor(Color.parseColor("#0D635B"));
                v_tab2.setVisibility(View.VISIBLE);

                et_cklx.setText(PrefeneceUtil.getData("para2_et_cklx_tab2","485串口",false));
                et_btl.setText(PrefeneceUtil.getData("para2_et_btl_tab2","9600",false));
                et_sjw.setText(PrefeneceUtil.getData("para2_et_sjw_tab2","8",false));
                et_tzw.setText(PrefeneceUtil.getData("para2_et_tzw_tab2","1",false));
                et_zyfs.setText(PrefeneceUtil.getData("para2_et_zyfs_tab2","无校验",false));
                break;
            case 3:
                net_type = 3;
                ll_area2.setVisibility(View.GONE);
                ll_area1.setVisibility(View.VISIBLE);
                ll_para_11.setVisibility(View.GONE);
                rl_tab3.setBackgroundColor(Color.parseColor("#F7F7F7"));
                tv_tab3.setTextColor(Color.parseColor("#0D635B"));
                v_tab3.setVisibility(View.VISIBLE);
                et_cklx.setText(PrefeneceUtil.getData("para2_et_cklx_tab3","485串口",false));
                et_btl.setText(PrefeneceUtil.getData("para2_et_btl_tab3","9600",false));
                et_sjw.setText(PrefeneceUtil.getData("para2_et_sjw_tab3","8",false));
                et_tzw.setText(PrefeneceUtil.getData("para2_et_tzw_tab3","1",false));
                et_zyfs.setText(PrefeneceUtil.getData("para2_et_zyfs_tab3","无校验",false));
                break;
            case 4:
                net_type = 4;
                ll_area2.setVisibility(View.GONE);
                ll_area1.setVisibility(View.VISIBLE);
                ll_para_11.setVisibility(View.GONE);
                rl_tab4.setBackgroundColor(Color.parseColor("#F7F7F7"));
                tv_tab4.setTextColor(Color.parseColor("#0D635B"));
                v_tab4.setVisibility(View.VISIBLE);
                et_cklx.setText(PrefeneceUtil.getData("para2_et_cklx_tab1","485串口",false));
                et_btl.setText(PrefeneceUtil.getData("para2_et_btl_tab1","9600",false));
                et_sjw.setText(PrefeneceUtil.getData("para2_et_sjw_tab1","8",false));
                et_tzw.setText(PrefeneceUtil.getData("para2_et_tzw_tab1","1",false));
                et_zyfs.setText(PrefeneceUtil.getData("para2_et_zyfs_tab1","无校验",false));
                break;
        }


    }

    private LinearLayout lyDlg;
    private TextView btn1, btn2,btn3,btn4,btn5,btn6,btn7, btnCancel;
    private Window window;

    @Override
    public void onClick(View view) {

        switch (view.getId()) {



            case R.id.ll_para_2:

                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                 window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn3 = (TextView) choosePicDialog.findViewById(R.id.btn3);
                btn4 = (TextView) choosePicDialog.findViewById(R.id.btn4);
                btn1.setText("串口");
                btn2.setText("红外");
                btn3.setText("蓝牙");
                btn4.setText("网口");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btn4.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        net_type = 1;
                        et_tcp.setText("串口");
                        ll_area2.setVisibility(View.GONE);
                        ll_area1.setVisibility(View.VISIBLE);
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        net_type = 2;
                        et_tcp.setText("红外");
                        ll_area2.setVisibility(View.GONE);
                        ll_area1.setVisibility(View.VISIBLE);
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });

                btn3.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        net_type = 3;
                        et_tcp.setText("蓝牙");
                        ll_area2.setVisibility(View.GONE);
                        ll_area1.setVisibility(View.VISIBLE);
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btn4.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        net_type = 4;
                        et_tcp.setText("网口");
                        ll_area2.setVisibility(View.VISIBLE);
                        ll_area1.setVisibility(View.GONE);
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;

            case R.id.ll_para_11:
                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn1.setText("232串口");
                btn2.setText("485串口");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        sevice_type = 1;
                        et_cklx.setText("232串口");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        sevice_type = 2;
                        et_cklx.setText("485串口");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });

                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;
            case R.id.ll_para_3:


                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                 window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn3 = (TextView) choosePicDialog.findViewById(R.id.btn3);
                btn1.setText("奇校验");
                btn2.setText("偶校验");
                btn3.setText("无校验");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        sevice_type = 1;
                        et_zyfs.setText("奇校验");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        sevice_type = 2;
                        et_zyfs.setText("偶校验");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });
                btn3.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        sevice_type = 3;
                        et_zyfs.setText("无校验");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;
            case R.id.ll_para_4:

                //（3）1200、4800、9600、115200，384000，默认为9600
                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn3 = (TextView) choosePicDialog.findViewById(R.id.btn3);
                btn4 = (TextView) choosePicDialog.findViewById(R.id.btn4);
                btn5 = (TextView) choosePicDialog.findViewById(R.id.btn5);
                btn1.setText("1200");
                btn2.setText("4800");
                btn3.setText("9600");
                btn4.setText("115200");
                btn5.setText("384000");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btn4.setVisibility(View.VISIBLE);
                btn5.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_btl.setText("1200");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_btl.setText("4800");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });

                btn3.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_btl.setText("9600");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btn4.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_btl.setText("115200");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btn5.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_btl.setText("384000");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;

            case R.id.ll_para_5:

                //（7、8、9、10，默认为8
                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn3 = (TextView) choosePicDialog.findViewById(R.id.btn3);
                btn4 = (TextView) choosePicDialog.findViewById(R.id.btn4);
                btn1.setText("7");
                btn2.setText("8");
                btn3.setText("9");
                btn4.setText("10");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btn4.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_sjw.setText("7");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_sjw.setText("8");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });

                btn3.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_sjw.setText("9");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btn4.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_sjw.setText("10");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;

            case R.id.ll_para_6:

                //（7、8、9、10，默认为8
                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn3 = (TextView) choosePicDialog.findViewById(R.id.btn3);
                btn4 = (TextView) choosePicDialog.findViewById(R.id.btn4);
                btn1.setText("1");
                btn2.setText("1.5");
                btn3.setText("2");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btn3.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_tzw.setText("1");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_tzw.setText("1.5");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });

                btn3.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_tzw.setText("2");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btn4.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_sjw.setText("10");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btn5.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_sjw.setText("384000");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;

            case R.id.ll_para_22:

                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn1.setText("TCP");
                btn2.setText("UDP");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_tcp2.setText("TCP");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();

                        et_tcp2.setText("UDP");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;

            case R.id.ll_para_23:


                choosePicDialog = new CustomDialog(SetParaTwoActivity.this, true);
                choosePicDialog.setCustomView(R.layout.pic_select_dlg);

                window = choosePicDialog.getDialog().getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setLayout(AbsoluteLayout.LayoutParams.MATCH_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT);

                lyDlg = (LinearLayout) choosePicDialog.findViewById(R.id.dialog_layout);
                lyDlg.setPadding(0, 0, 0, 0);

                btn1 = (TextView) choosePicDialog.findViewById(R.id.btn1);
                btn2 = (TextView) choosePicDialog.findViewById(R.id.btn2);
                btn1.setText("服务器");
                btn2.setText("客户端");
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                btnCancel = (TextView) choosePicDialog.findViewById(R.id.btnCancel);

                btn1.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        et_cs2.setText("服务器");
//                        Toast.makeText(SetParaOneActivity.this,"选择1",Toast.LENGTH_SHORT).show();
                    }
                });

                btn2.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                        et_cs2.setText("客户端");
//                        Toast.makeText(SetParaOneActivity.this,"选择2" ,Toast.LENGTH_SHORT).show();
                    }
                });
                btnCancel.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        choosePicDialog.dismiss();
                    }
                });

                choosePicDialog.setCancelable(true);
                choosePicDialog.show();

                break;

            case R.id.tv_back:
                finish();
                break;
            case R.id.tv_save:
//                LoadingDialog loadingDialog =  new LoadingDialog(this);
//                loadingDialog.setMessage("正在加载...").show();
//                loadingDialog.dismiss();


                TopToastUtil.getInstance(this,R.layout.showdialog_err).showShortToast("保存成功");

//                if("".equalsIgnoreCase(et_ip.getText().toString()))
//                {
//                    Toast.makeText(this,"请填写服务器ip",Toast.LENGTH_SHORT).show();
//                    return;
//                }
//                if("".equalsIgnoreCase(et_deveveid.getText().toString()))
//                {
//                    Toast.makeText(this,"请填写设备id",Toast.LENGTH_SHORT).show();
//                    return;
//                }
//                if("".equalsIgnoreCase(ed_msisdn.getText().toString()))
//                {
//                    Toast.makeText(this,"请填写设备msisdn",Toast.LENGTH_SHORT).show();
//                    return;
//                }

//                Consts.setServerIP(et_ip.getText().toString());
//                Consts.setdevice_id(et_deveveid.getText().toString());
//                Consts.setdevice_msisdn(ed_msisdn.getText().toString());

//                Toast.makeText(this,"设置完成",Toast.LENGTH_SHORT).show();

//                finish();
                break;
            case R.id.tv_set:
                hideSoftKeyboard(this);
                PrefeneceUtil.setData("para2_et_tcp",net_type+"",false);
                switch (net_type)
                {
                    case  1:
                        PrefeneceUtil.setData("para2_et_et_cs2",et_cs2.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_port2",et_port2.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_ip_bak2",et_ip_bak2.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_ip2",et_ip2.getText().toString(),false);

                        PrefeneceUtil.setData("para2_et_tcp2",et_tcp2.getText().toString()+"",false);

                        break;
                    case 2:
                        PrefeneceUtil.setData("para2_et_cklx_tab2",et_cklx.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_btl_tab2",et_btl.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_sjw_tab2",et_sjw.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_tzw_tab2",et_tzw.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_zyfs_tab2",et_zyfs.getText().toString(),false);
                        break;
                    case 3:
                        PrefeneceUtil.setData("para2_et_cklx_tab3",et_cklx.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_btl_tab3",et_btl.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_sjw_tab3",et_sjw.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_tzw_tab3",et_tzw.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_zyfs_tab3",et_zyfs.getText().toString(),false);
                        break;
                    case 4:


                        PrefeneceUtil.setData("para2_et_cklx_tab1",et_cklx.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_btl_tab1",et_btl.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_sjw_tab1",et_sjw.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_tzw_tab1",et_tzw.getText().toString(),false);
                        PrefeneceUtil.setData("para2_et_zyfs_tab1",et_zyfs.getText().toString(),false);
                        break;
                }







                    TopToastUtil.getInstance(this,R.layout.showdialog).showShortToast("保存成功");

                break;
            default:
                break;
        }


    }

    public static void hideSoftKeyboard(Activity activity) {
        View view = activity.getCurrentFocus();
        if (view != null) {
            InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

}

